// pages/CircleFriends/CircleFriends.js --create by cheese zhao
var app = getApp()
var that

Page({
  /**
   * 页面的初始数据
   */
  data: {
    DataSource: [1, 1, 1, 1, 1],
    icon: 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3175633703,3855171020&fm=27&gp=0.jpg',
    content: '我大学毕业到一家集团公司的办公室当文员。办公室主任有一特长，即文章写得好，很有思想，公司董事长很器重他，董事长的讲话稿和企业的年终总结等一系列重大文章都是出自他的手笔。',
    resource: ['http://img2.imgtn.bdimg.com/it/u=2118739199,3378602431&fm=27&gp=0.jpg',
      'http://img0.imgtn.bdimg.com/it/u=2277942808,1417432970&fm=27&gp=0.jpg',
      'http://img5.imgtn.bdimg.com/it/u=1504812505,3480403568&fm=27&gp=0.jpg',
      'http://img4.imgtn.bdimg.com/it/u=3456219059,4251129897&fm=27&gp=0.jpg',
      'http://img3.imgtn.bdimg.com/it/u=3912316188,1981132393&fm=27&gp=0.jpg'
    ],
    zanSource: ['张三', '李四', '王五', '找钱', '孙俪', '王宝','T_T'],
    contnet: [{
        'firstname': '张三',
        'content': '你好漂亮呀！！'
      },
      {
        'firstname': '李四',
        'content': '纳尼！！'
      },
      {
        'firstname': '王五',
        'content': '鬼扯咧'
      },
      {
        'firstname': '王宝',
        'content': '昨晚11点左右，一则郑爽胡彦斌疑似复合的消息刷爆各大论坛，微博在深夜11点热度高达200万直接爆掉，中国意难忘又开始了！！！'
      }
    ],
    photoWidth: wx.getSystemInfoSync().windowWidth / 5,

    popTop: 0, //弹出点赞评论框的位置
    popWidth: 0, //弹出框宽度
    isShow: true, //判断是否显示弹出框
    me:{},
    backgroundImageUrl:"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.16pic.com%2F00%2F00%2F85%2F16pic_85878_b.jpg&refer=http%3A%2F%2Fpic1.16pic.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1628260164&t=a1d0d0459df2f3008c43e30b64c3d98c",
    userInfo: {},
    hasUserInfo: false,
    canIUseGetUserProfile: false,
  

    goodJobIcon:"",
    reviewJobIcon:"",
    animationData:{},
    reviewPopSw:false,
    focus: false,
    reviewContent:"",

    windowHeight:"650",
    navBarBGL:"transparent",

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    that = this
    //获取用户手机创库高度
    wx.getSystemInfo({
      success: (result) => {
        
        this.setData({
          windowHeight:result.windowHeight
        })
      },
    })
    //获取用户信息，note：2021-4 月以后原先的方式不在可取
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },
  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认
    // 开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    wx.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res);
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    });
    console.log(this.userInfo)
  },
  getUserInfo(e) {
    // 不推荐使用getUserInfo获取用户信息，预计自2021年4月13日起，getUserInfo将不再弹出弹窗，并直接返回匿名的用户个人信息
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  // 点击图片进行大图查看
  LookPhoto: function(e) {
    wx.previewImage({
      current: e.currentTarget.dataset.photurl,
      urls: this.data.resource,
    })
  },

  // 点击点赞的人
  TouchZanUser: function(e) {
    wx.showModal({
      title: e.currentTarget.dataset.name,
      showCancel: false
    })
  },

  // 删除朋友圈
  delete: function() {
    wx.showToast({
      title: '删除成功',
    })
  },

  // 点击了点赞评论
  TouchDiscuss: function(e) {
    // this.data.isShow = !this.data.isShow
    // 动画
    var animation = wx.createAnimation({
      duration: 300,
      timingFunction: 'linear',
      delay: 0,
    })
    that.animation = animation

    if (that.data.isShow == false) {
      that.setData({
        popTop: e.target.offsetTop - (e.detail.y - e.target.offsetTop) / 2,
        popWidth: 0,
        isShow: true
      })

      // 0.3秒后滑动
      setTimeout(function() {
        animation.width(0).opacity(1).step()
        that.setData({
          animationData: animation.export(),
          
        })
      }, 100)
    } else {
      // 0.3秒后滑动
      setTimeout(function() {
        animation.width(120).opacity(1).step()
        that.setData({
          animationData: animation.export(),
          
        })
      }, 100)

      that.setData({
        popTop: e.target.offsetTop - (e.detail.y - e.target.offsetTop) / 2,
        popWidth: 0,
        isShow: false
      })

    }
  },
  //父节点上（外层点击事件）关闭点赞评论框,关闭评论输入框
  closeGoodJobReviewAll(){
    if (that.data.isShow == false) {
      that.animation.width(0).opacity(1).step()
        that.setData({
          animationData: that.animation.export(),
         
        })
        that.setData({
          isShow:true,
        })
          
    }
    if (this.data.reviewPopSw){
      that.setData({
        reviewPopSw:false,
      })
    }
  },
  closeGoodJobReview: function(e){
    var animation = wx.createAnimation({
      duration: 300,
      timingFunction: 'linear',
      delay: 0,
    })
    this.animation = animation
    if (that.data.isShow == false) {
      that.setData({
        popTop: e.target.offsetTop - (e.detail.y - e.target.offsetTop) / 2,
        popWidth: 0,
        isShow: true
      })
      animation.width(0).opacity(1).step()
        that.setData({
          animationData: animation.export(),
          
        })
      
    }
  },
  bubbingTap: function(e){
    console.log("touch bubbing")
    console.log(this.data.isShow)
    if(this.data.isShow){
       this.closeGoodJobReview(e);
    } 
    
  },
  //点赞后逻辑处理
  isGoodJob: function(e) {
    this.closeGoodJobReview(e);
    console.log(this.data.userInfo)
    this.data.zanSource.push(this.data.userInfo.nickName);
    var arr = this.data.zanSource;
    console.log(arr)
    this.setData({
      zanSource:arr
    })
  },

  //弹起评论输入框
  pupUpReviewdBox:function(e){
    var pop=!that.data.reviewPopSw
    that.setData({
      reviewPopSw:pop
    })
    this.closeGoodJobReview(e)
  },
  //添加一条评论
  addReview:function(e){
    //添加到对应的朋友的圈

  },

  cancelGoodJob:function(e) {
    // 找到对应的朋友圈，删掉我的点赞

  },

  cancelReview:function(e){
    //直接长按删除对应的评论
  },

  // 评论框对应交互
  bindReply(e) {
    this.setData({
      focus: true
    });
  },
  contentInput(e) { //当输入框的值发生改变时，获取
    this.setData({
      reviewContent: e.detail.value
    });
  },
  comment(e){
    var review = this.data.reviewContent
    console.log(review.length)
    if(review.length>0){
      console.log(review.length)
      this.data.contnet.push({
        
          'firstname': this.data.userInfo.nickName,
          'content': review
        
      })
      var arr = this.data.contnet;
      this.setData({
        contnet:arr,
        reviewPopSw:false
      })
    }
  },
  backNav(e){
    wx.navigateBack()
  },

  upperEvent(e){
    
   if(e.detail.scrollTop>193){
     this.setData({
      navBarBGL:"#4427A3"
     })
   } else {
     this.setData({
       navBarBGL:"transparent"
     })
   }
    
  },
  // tap the icon of camera than navigate to page for add a every day moment
  sentPhoto(){
    
  }
})